package tinybase.rm;

import tinybase.basic.RC;
import tinybase.basic.RedBase;

public class RM_Errors {
	
	//
	// Error table
	//
	static String[] RM_WarnMsg = {
		"inviable rid",
		"unread record",
		"invalid record size",
		"invalid slot number",
		"record not found",
		"invalid comparison operator",
		"invalid attribute parameters",
		"null pointer",
		"scan open",
		"scan closed",
		"file closed" 
	};
	
	static String[] RM_ErrorMsg= {
		"no memory"
	};
	
	// 
	// RM_PrintError
	//
	// Desc: Send a message corresponding to a RM return code to cerr
	// In:   rc - return code for which a message is desired
	//
	
	public static void printError(RC rc) {
		// Check the return code is within proper limits
		if ((rc.getValue() >= RedBase.START_RM_WARN) &&
				(rc.getValue() <= RC.RM_LASTWARN.getValue()))
			// Print warning
			System.err.println("RM warning: " + 
					RM_WarnMsg[rc.getValue() - RedBase.START_RM_WARN]);
		// Error codes are negative, so invert everything
		else if ((0-rc.getValue()) >= (0-RedBase.START_RM_ERR) &&
				(0-rc.getValue()) <= (0-RC.RM_LASTERROR.getValue()))
			// Print Errors
			System.err.println("RM error: " + RM_ErrorMsg[0-rc.getValue()
			        + RedBase.START_RM_ERR]);
		else if (rc.getValue() == 0)
			System.err.println("RM_PrintError called with return code of 0");
		else
			System.err.println("RM error: " + rc.getValue() + 
					" is out of bounds");
	}

	
}
